require 'test/unit'
require 'lib/smppclient/pdu/bind_transmitter'

class TestBindTransmitter < MiniTest::Unit::TestCase

  include SmppClient::Pdu
  include SmppClient::Util

  def test_bytes_to_object
    bb = ByteBuffer.new
    bb.append_int(58)
    bb.append_int(2)
    bb.append_int(13)
    bb.append_int(2000123456)
    bb.append_cstring('miluoki')
    bb.append_cstring('asim')
    bb.append_cstring('yakamoto')
    bb.append_byte(10)
    bb.append_byte(5)
    bb.append_byte(14)
    bb.append_cstring('romaromaromaroma')

    bt = BindTransmitter.new(bb)
    assert_equal(58, bt.command_length)
    assert_equal(CommandId::BIND_TRANSMITTER, bt.command_id)
    assert_equal(CommandStatus::ESME_RBINDFAIL, bt.command_status)
    assert_equal(2000123456, bt.sequence_number)
    assert_equal('miluoki', bt.system_id)
    assert_equal('asim', bt.password)
    assert_equal('yakamoto', bt.system_type)
    assert_equal(10, bt.interface_version)
    assert_equal(5, bt.addr_ton)
    assert_equal(14, bt.addr_npi)
    assert_equal('romaromaromaroma', bt.address_range)
  end

  def test_object_to_bytes
    bt = BindTransmitter.new
    bt.command_status = CommandStatus::ESME_RINVSRCADR
    bt.sequence_number = 1921041
    bt.system_id = 'abakan'
    bt.password = 'chertog'
    bt.system_type = 'closure'
    bt.interface_version = 168
    bt.addr_ton = Ton::NETWORK_SPECIFIC
    bt.addr_npi = Npi::DATA
    bt.address_range = 'all can'
    assert_equal('00000032000000020000000a001d50116162616b616e0063686572746f6700636c6f7375726500a80303616c6c2063616e00', bt.buffer.to_s)
  end

end